﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tauren.Business.Entity.Model;
using Tauren.Business.Infrastructure;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.WorkBenchBLL;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 工作台
    /// </summary>
    [Route("api/workbench")]
    [ApiController]
    public class WorkBenchController : ControllerBase
    {
        private IWorkBenchService service;

        /// <summary>
        /// 工作台构造函数
        /// </summary>
        /// <param name="_services"></param>
        public WorkBenchController(IEnumerable<IWorkBenchService> _services)
        {
            this.service = _services.FirstOrDefault(o => o.Version == 1.0);
            if (this.service == null) throw new ApiVersionException("不支持当前版本");
        }
        /// <summary>
        /// 获取流程工作台
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}")]
        [ApiVersion("1.0")]
        [ApiVersion("2.0")]
        public IActionResult Pages() => service.GetWorkBenchs().ToJsonResult();

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/save")]
        [ApiVersion("1.0")]
        [ApiVersion("2.0")]
        public IActionResult Save([FromBody] List<Flow_WorkBench> input) => service.AddWorkBenchs(input).ToJsonResult();

        /// <summary>
        /// 获取所有流程工作台
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/benchs")]
        [ApiVersion("1.0")]
        [ApiVersion("2.0")]
        public IActionResult GetAllWorkBenchs() => service.GetAllWorkBenchs().ToJsonResult();

    }
}
